#include "UdpConnMgr.hpp"
#include "DeviceMgr.hpp"
#include "KieperException.hpp"
#include "GetAccelReading.hpp"
#include "GetAccelReadingReply.hpp"

#include <iostream>

static const char* UDP_HOST = "192.168.0.65";
static const int UDP_PORT = 1111;

using namespace kieper;

int main() {
    std::cout<<"In main:"<<std::endl;
    try {
        DeviceMgr devMgr;
        ConnMgr* connMgr = new UdpConnMgr(UDP_HOST, UDP_PORT);
        devMgr.addConnMgr(connMgr);
        devMgr.findDevices();
        devMgr.startPacketProcessors();
        Device& device = devMgr.getDevice(111);
 
        for (unsigned int i = 0; i < 10; ++i) {       
            GetAccelReading getAccMsg;
            std::cout<<"In sending acc msg"<<std::endl;
            IncomingPacketPtr pkt = device.sendSyncMsg(getAccMsg);
            std::cout<<"Got reply"<<std::endl;
            GetAccelReadingReply reply(*pkt);
            std::cout<<"x = "<<reply.getAccelX() << " y = " << reply.getAccelY() << std::endl;
        }

    } catch (KieperException& e) {
        std::cout << "Exception caught!" << std::endl;
        std::cout << e.longMsg() << std::endl;
    }
}
